clear
set more off

use $tempdir/panel_trends_30yr_income.dta, clear

gen     broad_occ = 0 if occ1950 == 100 | occ1950 == 123
label define broad_occ 0 "Farmer"

replace broad_occ = 1 if occ1950 >= 0 & occ1950 <= 290 & occ1950!= 100 & occ1950 != 123
label define broad_occ 1 "Prof & Manag", add

replace broad_occ = 2 if occ1950 >= 300 & occ1950 <= 490 
label define broad_occ 2 "Clerical & Sales", add

replace broad_occ = 3 if occ1950 >= 500 & occ1950 <= 690 
label define broad_occ 3 "Skilled", add

replace broad_occ = 4 if occ1950 >= 700 & occ1950 <= 970
label define broad_occ 4 "Unskilled", add

label values broad_occ broad_occ

keep if race == 1
gen anyocc = occ1950 < 980
gen log_ownoccscore = log(occscore+1)

collapse (mean) anyocc log_ownoccscore, by(urban ever_married sex year2)

gen birth_cohort = year2 - 37.5 

graph twoway scatter anyocc birth_cohort if ever_married==1 & urban == 2 & sex==2, sort(year2) connect(direct) lcolor(gs8) lwidth(thick) lpattern(dash) mcolor(gs8) msymbol(circle)  || /*
	*/ scatter anyocc birth_cohort if ever_married==1 & urban == 1 & sex==2, sort(year2) connect(direct) lcolor(gs8) lwidth(thick) lpattern(solid) mcolor(gs8) msymbol(triangle)  || /*
	*/ scatter anyocc birth_cohort if ever_married==0 & urban == 2 & sex==2, sort(year2) connect(direct)  lcolor(gs0) lwidth(thick) lpattern(dash) mcolor(gs0) msymbol(circle) || /*
	*/ scatter anyocc birth_cohort if ever_married==0 & urban == 1 & sex==2, sort(year2) connect(direct) lcolor(gs0) lwidth(thick) lpattern(solid) mcolor(gs0) msymbol(triangle) /*
	*/ legend(label(1 "Married, Urban") label(2 "Married, Rural") label(3 "Never Married, Urban") label(4 "Never Married, Rural")) graphregion(fcolor(white) lcolor(white)) /*
	*/ xtitle("15 year birth cohort") title("Share with Any Occupation") /*) "By Marriage and Urban Status") subtitle("`title`x'' Women, Ages 30-45")*/ ytitle("Share") ylab(0(0.2)1)
	
graph export "$outputdir/nvrmarrwomen_anyocc.pdf", replace
	

use $tempdir/panel_trends_30yr_income.dta, clear

keep if race == 1
gen anyocc = occ1950 < 980
gen log_ownoccscore = log(occscore+1)

collapse (mean) anyocc log_ownoccscore, by(urban ever_married sex year2)

gen birth_cohort = year2 - 37.5 

graph twoway scatter log_ownoccscore birth_cohort if ever_married==1 & urban == 2 & sex==2, sort(year2) connect(direct) lcolor(gs8) lpattern(dash) lwidth(thick) mcolor(gs8) msymbol(circle)  || /*
	*/ scatter log_ownoccscore birth_cohort if ever_married==1 & urban == 1 & sex==2, sort(year2) connect(direct) lcolor(gs8) lwidth(thick) mcolor(gs8) msymbol(triangle)  || /*
	*/ scatter log_ownoccscore birth_cohort if ever_married==0 & urban == 2 & sex==2, sort(year2) connect(direct)  lcolor(gs0) lpattern(dash) lwidth(thick) mcolor(gs0) msymbol(circle) || /*
	*/ scatter log_ownoccscore birth_cohort if ever_married==0 & urban == 1 & sex==2, sort(year2) connect(direct) lcolor(gs0) lwidth(thick) mcolor(gs0) msymbol(triangle) /*
	*/ legend(label(1 "Married, Urban") label(2 "Married, Rural") label(3 "Never Married, Urban") label(4 "Never Married, Rural")) graphregion(fcolor(white) lcolor(white)) /*
	*/ xtitle("15 year birth cohort") title("Mean Log Occscore") /* "By Marriage and Urban Status") subtitle("`title`x'' Women, Ages 30-45")*/ ytitle("Log Occscore")
	
graph export "$outputdir/nvrmarrwomen_occscore.pdf", replace	

use $tempdir/panel_trends_30yr_income.dta, clear

keep if race == 1
gen anyocc = occ1950 < 980
keep if sex == 2 & anyocc == 1

collapse (count) numinocc = serial, by(occ1950 occscore urban ever_married sex year2)
	
gsort sex year2 ever_married urban -numinocc	
by sex year2 ever_married urban: egen numemployed = total(numinocc)
by sex year2 ever_married urban: gen occrank = _n

gen shareinocc = numinocc / numemployed
keep if occrank <= 25	
	
export excel using "$outputdir\Top Occs by Urban and Married.xlsx", firstrow(var) keepcellfmt replace

	
	
	